/**
 * Created by Jackie on 2017/2/22.
 */
function demo(value) {
    try {

    } catch (e) {
        throw Error(e)
    }
    return value
}
function toFixed(value, digits = 2) {
    try {
        value = parseInt(value, 10)
    } catch (e) {
        throw Error(e)
    }
    return value.toFixed(digits)
}
function orderStatusFilter(value) {
    try {
        switch (value) {
            case '0' :
                value = '待支付';
                break;
            case '1' :
                value = '已支付';
                break;
            case '2' :
                value = '已完成';
                break;
            case '3' :
                value = '已取消';
                break;
            case '5' :
                value = '已取消';
                break;
        }
    } catch (e) {
        throw Error(e)
    }
    return value
}
function timeLagFilter(value) {
    if (!value) {
        return '';
    }
    const before = new Date(value); // 接口给出的时间
    const now = new Date();         // 本地时间
    if (now.getFullYear() - before.getFullYear() > 0) {
        return `${now.getFullYear() - before.getFullYear()}年`
    } else if (now.getMonth() - before.getMonth() > 0) {
        return `${now.getMonth() - before.getMonth()}个月`
    } else if (now.getDate() - before.getDate() > 0) {
        return `${now.getDate() - before.getDate()}天前`
    } else if (now.getHours() - before.getHours() > 0) {
        return `${now.getHours() - before.getHours()}小时`
    } else if (now.getMinutes() - before.getMinutes() > 0) {
        return `${now.getMinutes() - before.getMinutes()}分钟`
    } else if (now.getSeconds() - before.getSeconds() > 0) {
        return `${now.getSeconds() - before.getSeconds()}秒钟`
    } else {
        return '1秒钟';
    }
}
function urlFilterAddServer(value) {
    let url = (/(http)/.test(value)) ? value : `${window.location.origin}${value}`;
    return url
}

// 将时间戳转为该时间格式：yyyy-mm-dd hh:mm:ss
function longTimeStr(value) {
    if (value) {
        const DATE = new Date(value);

        // 年
        const Y = DATE.getFullYear();
        // 月
        const MONTH = DATE.getMonth() + 1;
        const M = MONTH < 10 ? `0${MONTH}` : MONTH;
        // 日
        const DAY = DATE.getDate();
        const D = DAY < 10 ? `0${DAY}` : DAY;
        // 时
        const HOUR = DATE.getHours();
        const h = HOUR < 10 ? `0${HOUR}` : HOUR;
        // 分
        const MINUTE = DATE.getMinutes();
        const m = MINUTE < 10 ? `0${MINUTE}` : MINUTE;
        // 秒
        const SECOND = DATE.getSeconds();
        const s = SECOND < 10 ? `0${SECOND}` : SECOND;

        return `${Y}-${M}-${D} ${h}:${m}:${s}`;
    }

    return '0000-00-00 00:00:00';
}
function cityNameFilter4(value) {
    if (value && value.length > 4) {
        return value.substring(0, 4);
    }
    return value;
}
function cityNameFilter6(value) {
    if (value && value.length > 6) {
        return value.substring(0, 6);
    }
    return value;
}
export default [
    {toFixed},
    {orderStatusFilter},
    {timeLagFilter},
    {urlFilterAddServer},
    {longTimeStr},
    {cityNameFilter4},
    {cityNameFilter6},
]
